package com.kejiguan.ui.presenter;

import android.text.TextUtils;
import android.widget.Toast;

import com.android.volley.error.VolleyError;
import com.android.volley.response.Response;
import com.kejiguan.ui.model.UserManagerModer;
import com.kejiguan.ui.request.GsonRequest;
import com.kejiguan.ui.request.RequestUtil;
import com.kejiguan.ui.response.ClearWorkOrderResponse;
import com.kejiguan.ui.response.ModifyUserPassResponse;
import com.kejiguan.ui.response.ModifyUserResponse;
import com.kejiguan.ui.util.CacheDataUtil;
import com.kejiguan.ui.util.CommonDate;
import com.kejiguan.ui.util.DateFormatUtil;

import org.greenrobot.eventbus.EventBus;

import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by YYY on 2016/5/1.
 */
public class UserInfoFragmentPresenter extends BaseFragmentPresenter{

    public void modifyUser(String  userId,String newPass)
    {
        long currentTime=System.currentTimeMillis();
        String currentDate=String.valueOf(currentTime);
        try {
            currentDate= DateFormatUtil.longToString(currentTime, "yyyyMMdd");
        } catch (ParseException e) {
            e.printStackTrace();
        }


        Map<String,String> params=new HashMap<>();
        params.put("requestCode","711");
        params.put("messageId",currentDate+"S"+currentTime);
        params.put("systemCode", CommonDate.SystemCode);
        params.put("operType","modPwd");
        params.put("uId",userId);
        params.put("userPassword", newPass);


        final GsonRequest<ModifyUserPassResponse> request = new GsonRequest("modUserPass", ModifyUserPassResponse.class, new Response.Listener<ModifyUserPassResponse>() {
            @Override
            public void onResponse(ModifyUserPassResponse response) {
                EventBus.getDefault().post(response);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

                Toast.makeText(mContext, "修改密码失败！", Toast.LENGTH_SHORT).show();

            }
        });

        RequestUtil.sendRequest(mContext, params, request);
    }

    public void clearWorkOrder()
    {
        long currentTime=System.currentTimeMillis();
        String currentDate=String.valueOf(currentTime);
        try {
            currentDate= DateFormatUtil.longToString(currentTime, "yyyyMMdd");
        } catch (ParseException e) {
            e.printStackTrace();
        }


        Map<String,String> params=new HashMap<>();
        params.put("requestCode","715");
        params.put("messageId",currentDate+"S"+currentTime);
        params.put("systemCode", CommonDate.SystemCode);

        final GsonRequest<ClearWorkOrderResponse> request = new GsonRequest("clearWorkOrder", ClearWorkOrderResponse.class, new Response.Listener<ClearWorkOrderResponse>() {
            @Override
            public void onResponse(ClearWorkOrderResponse response) {
                EventBus.getDefault().post(response);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

                Toast.makeText(mContext, "清除工单失败！", Toast.LENGTH_SHORT).show();

            }
        });

        RequestUtil.sendRequest(mContext, params, request);
    }
}
